*===============================================================================
*Firm and Country Embedded Productivity (Alviarez, Cravino and Ramondo) 
*Correlation (Table 2 in the paper) (by OLS) 
*Last Modified by Vanessa Alviarez 02/2021
*===============================================================================
global typeden=1
include "TFP_firm_directory_historical.do"
set more off
clear all


/*
*==================================================================================
*Correlation with factors TFP
*==================================================================================
local mastervar "_sales"

*This is in headings (called in the master file) Erase it after it has its name in headings do file
local ending "" /* "_gap" */
local zz naics  /*naics, naics3, naics4*/
local var0 "`mastervar'" 
local name "_base" /*"_base", "_exclnomark", "_growth`xx'years" */
local name1 "_woparent" /* "_guoFEcte" "_growth`grnum'years", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  /*samp2 includes AU, DK and NO*/
global ctryrel FR
local typeused "agg"
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"
*---------------------------------------
local abslist "year"
local clusterlist "isocode"
local variablelist "k_y ln_hc" /* ln_RuleofLaw*/ 
local rho=8.5

local nn=10
local sample `" isocode=="" "'

clear all
use "${output}/estimates_sec_`title'.dta", clear
by year isocode, sort: egen num=count( fe_location )
table isocode year, c(mean  num)
keep if num>=`nn'
keep year isocode
duplicates drop 
tempfile iso
save `iso', replace 

use "${output}/estimates_`typeused'_`title'.dta", clear
merge m:1 year isocode using `iso'
keep if _merge==3
drop _merge
drop if D_A==. | (D_A==0 & isocode!="FR")
drop if `sample'  


merge m:1 year isocode type using "${output}/aggregates_tfp_lp_klems_agg.dta" 
drop if _merge==2
drop _merge
gen k_y=ln_ck-ln_rgdpo	
local grvar0 "ctfp" /*"rtfpna"; ..."LP1TFP_I_klems" ctfp gdp_pw_ppp gdp_pc_ppp gdp_pc_curr */

gen D_A_phi=(-1)*D_A/(`rho' -1)
gen b_phi=ln_`grvar0' - D_A_phi


local yy=2016
local var_dep "ln_`grvar0'"
reghdfe `var_dep' `variablelist' if year==`yy', abs(`abslist')  
*vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"



foreach yy in 2016  {
display "`yy'"

*TFP (year)
*----------------------------------------
local var_dep "ln_`grvar0'"
reghdfe `var_dep' `variablelist' if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"
outreg2 using "${results}/tables/correlation_table`var0'.xls", br ctitle(OLS levels, type: "agg (tfp), year `yy'", var_dep: `var_dep', FE: `abslist', cluster (`clusterlist')) replace 


*PHI TFP (year)
*----------------------------------------
local var_dep "D_A_phi"
reghdfe `var_dep'  `variablelist' if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"
outreg2 using "${results}/tables/correlation_table`var0'.xls", br ctitle(OLS levels, type: "agg (tfp), year `yy'", var_dep: `var_dep', FE: `abslist', cluster (`clusterlist')) append 


*Z TFP (year)
*----------------------------------------
local var_dep "b_phi"
reghdfe `var_dep'  `variablelist' if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"
outreg2 using "${results}/tables/correlation_table`var0'.xls", br ctitle(OLS levels, type: "agg (tfp), year `yy'", var_dep: `var_dep', FE: `abslist', cluster (`clusterlist')) append 

}
*
*/


*==================================================================================
*Correlation with factors (Labor Productivity) aggregate across sectors 
*==================================================================================
local mastervar "_sales"


*This is in headings (called in the master file) Erase it after it has its name in headings do file
local ending "" 
* "_gap" */
local zz naics  
*naics, naics3, naics4*/
local var0 "`mastervar'" 
local name "_base" 
*"_base", "_exclnomark", "_growth`xx'years" */
local name1 "_woparent" 
* "_guoFEcte" "_growth`grnum'years", "_fullgrav", "_nograv","_dist2", "_gdpgap" "_pctile`x'", "_woGUOFE", "_woisoFE", "_min`xx'years", "_LHSlevels", "_growth`xx'years", ALL OF WHICH ARE INDIVIDUAL DEPARTURES FROM THE BASELINE*/
local samp=4  
*samp2 includes AU, DK and NO*/
global ctryrel FR
local typeused "agg"
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"
*---------------------------------------
local rho=8.5
local rr ""
local nn=10
local sample `" isocode=="" "'


clear all
use "${output}/estimates_sec_`title'.dta", clear
by year isocode, sort: egen num=count( fe_location )
table isocode year, c(mean  num)
keep if num>=`nn'
keep year isocode
duplicates drop 
tempfile iso
save `iso', replace 

use "${output}/estimates_`typeused'_`title'.dta", clear
merge m:1 year isocode using `iso'
keep if _merge==3
drop _merge
drop if D_A==. | (D_A==0 & isocode!="FR")
drop if `sample'  

merge m:1 year isocode type using "${output}/aggregates_tfp_lp_klems_agg.dta" 
drop if _merge==2
drop _merge

merge m:1 year isocode using "${inputs}/additional_agg_indicators.dta"
drop if _merge==2
drop _merge

merge m:1 isocode using "${inputs}/bloom_management.dta"
drop if _merge==2
drop _merge

*-------------------------------------------------------
gen k_y=ln_ck-ln_rgdpo	
local grvar0 "gdp_pw_ppp" 
*"rtfpna"; ..."LP1TFP_I_klems" ctfp gdp_pw_ppp gdp_pc_ppp gdp_pc_curr */

gen D_A_phi=(-1)*D_A/(`rho' -1)
*Fixing the labor share in 2/3
*---------------------------------------
replace inv_labsh`rr'=1.5
*---------------------------------------
gen b_phi=ln_`grvar0' - inv_labsh`rr'*D_A_phi
replace D_A_phi=D_A_phi*inv_labsh`rr'

local abslist "year"
local clusterlist "isocode"
local variablelist "k_y ln_hc RuleofLaw"
local yy=2016
tempfile temp
save `temp', replace

*----------------------------------------
*Variables transformation 
use `temp', clear
keep if year==2016

gen xx=trademark_application if isocode=="AT"
egen yy=max(xx)
replace trademark_application=yy if isocode=="NL"
drop xx yy

gen ln_infrastructure=ln(infrastructure) 
gen ln_patent=ln(patent_total)
gen ln_patent_pc=ln_patent-ln_pop
gen ln_trademark=ln(trademark_application)
gen ln_trademark_pc=ln_trademark-ln_pop
gen ln_researcher_permm=ln(Researchers_RD_permm)
gen ln_mobile_per100=ln(mobile_per100) 
gen ln_broadband_per100=ln(broadband_per100) 
gen ln_electric_pc=ln(electric_percapita) 
gen ln_freshwater_pc=ln(freshwater_percapita) 
gen ln_air_transp=ln(air_transp) 
gen ln_container_port=ln(container_port)
gen ln_schooling=ln(schooling)
gen ln_manag_large=ln(manag_large)
gen ln_manag_small=ln(manag_small)
egen gov_index=rowmean(PoliticalStability GovernmentEffectiveness RegulatoryQuality RuleofLaw ControlofCorruption)
egen gov_rank_index=rowmean(PoliticalStability_rank GovernmentEffectiveness_rank RegulatoryQuality_rank RuleofLaw_rank ControlofCorruption_rank)

*Management Practices (Bloom)
*----------------------------------------
scatter D_A_phi ln_manag_small
reg D_A_phi ln_manag_large
pwcorr  D_A_phi ln_manag_large, sig star(.1)
local corr : di %4.3f r(rho)
display "`corr'"
local R2 : di %4.3f e(r2)

local ytitle "{&Delta}`=ustrunescape("\u03D5\u0303")'{sub:n}"
graph twoway (lfit D_A_phi ln_manag_large, lcolor(red)) (scatter D_A_phi ln_manag_large, msymbol(circle_hollow) mcolor(red) mlabel(isocode) mlabcolor(red)  msize(medium) mlabsize(small) ),  ylabel(-0.4(0.2)0.2) xlabel(-0.08(0.04)0.06) ytitle("`ytitle'") xtitle("Average Management Practices") subtitle("") graphregion(color(white)) bgcolor(white) legend(order(1 "R2:`R2'") size(small) bplace(se) ring(0) region(lwidth(none))) 
*graph twoway (lfit ln_manag_large D_A_phi ) (scatter  ln_manag_large D_A_phi, mlabel(isocode) ), xlabel(-0.4(0.2)0.2)  ylabel(-0.08(0.04)0.08) ytitle("Management Practices") xtitle("`ytitle'") subtitle(correlation "`corr'") graphregion(color(white)) bgcolor(white) legend(off)
*graph twoway (lfit D_A_phi ln_manag_large) (scatter D_A_phi ln_manag_large, mlabel(isocode) ),  ylabel(-0.4(0.2)0.2) xlabel(-0.08(0.04)0.08) ytitle("Phi") xtitle("Management") graphregion(color(white)) bgcolor(white) legend(off)
graph export "${results}/figures/scatter_phi_management.pdf", as(pdf) name("Graph") replace

scatter b_phi ln_manag_small
reg b_phi ln_manag_large
pwcorr  b_phi ln_manag_large, sig star(.1)
local corr : di %4.3f r(rho)
display "`corr'"
local R2 : di %4.3f e(r2)

local ytitle "{&Delta}`=ustrunescape("\u007A\u0303")'{sub:n}"
graph twoway (lfit b_phi ln_manag_large, lcolor(blue)) (scatter b_phi ln_manag_large, msymbol(circle_hollow) mcolor(blue) mlabel(isocode) mlabcolor(blue)  msize(medium) mlabsize(small) ),  ylabel(-0.8(0.2)0.2) xlabel(-0.08(0.04)0.06) ytitle("`ytitle'") xtitle("Average Management Practices") subtitle("") graphregion(color(white)) bgcolor(white) legend(order(1 "R2:`R2'") size(small) bplace(se) ring(0) region(lwidth(none))) 
*graph twoway (lfit ln_manag_large D_A_phi ) (scatter  ln_manag_large D_A_phi, mlabel(isocode) ), xlabel(-0.4(0.2)0.2)  ylabel(-0.08(0.04)0.08) ytitle("Management Practices") xtitle("`ytitle'") subtitle(correlation "`corr'") graphregion(color(white)) bgcolor(white) legend(off)
*graph twoway (lfit D_A_phi ln_manag_large) (scatter D_A_phi ln_manag_large, mlabel(isocode) ),  ylabel(-0.4(0.2)0.2) xlabel(-0.08(0.04)0.08) ytitle("Phi") xtitle("Management") graphregion(color(white)) bgcolor(white) legend(off)
graph export "${results}/figures/scatter_Z_management.pdf", as(pdf) name("Graph") replace


*Management Practices (Bloom) (Z and phi together) 
*----------------------------------------
scatter D_A_phi ln_manag_small
reg D_A_phi ln_manag_large
pwcorr  D_A_phi ln_manag_large, sig star(.1)
local corr_phi : di %4.3f r(rho)
display "`corr_phi'"
local R2_phi : di %4.3f e(r2)

scatter b_phi ln_manag_small
reg b_phi ln_manag_large
pwcorr  b_phi ln_manag_large, sig star(.1)
local corr_Z : di %4.3f r(rho)
display "`corr_Z'"
local R2_Z : di %4.3f e(r2)

local ytitle "{&Delta}`=ustrunescape("\u03D5\u0303")'{sub:n}, {&Delta}`=ustrunescape("\u007A\u0303")'{sub:n}"
graph twoway (lfit D_A_phi ln_manag_large, lcolor(red)) (scatter D_A_phi ln_manag_large, msymbol(circle_hollow) mcolor(red) mlabel(isocode) mlabcolor(red)  msize(medium) mlabsize(small) )  (line ln_manag_large ln_manag_large, lcolor(none)) (lfit b_phi ln_manag_large, lcolor(blue)) (scatter b_phi ln_manag_large, msymbol(square_hollow) mcolor(blue) mlabel(isocode) mlabcolor(blue)  msize(medium) mlabsize(small) )  (line ln_manag_large ln_manag_large, lcolor(none)) ,  ylabel(-0.8(0.2)0.2) xlabel(-0.08(0.04)0.06) ytitle("`ytitle'") xtitle("Average Management Practices") subtitle("") graphregion(color(white)) bgcolor(white) legend(order(1 "R2:`R2_phi'" 4 "R2:`R2_Z'") rows(2) size(small) bplace(se) ring(0) region(lwidth(none))) 
graph export "${results}/figures/scatter_phi_Z_management.pdf", as(pdf) name("Graph") replace









*PHI LP (year)
*----------------------------------------
local var_dep "D_A_phi"
local typefirm "ln_patent_pc"
local abslist "year"
local clusterlist "isocode"
local variablelist "k_y ln_hc RuleofLaw"
local yy=2016
local grvar0 "gdp_pw_ppp" 

foreach vardep in "ln_`grvar0'" "D_A_phi" "b_phi"  {
display "`vardep'"

reghdfe `vardep' k_y ln_hc  if year==2016, abs(`abslist')  vce(cluster `clusterlist')
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c4_rank).xls", br ctitle(OLS levels, type: "agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 

reghdfe `vardep' k_y ln_hc ln_broadband_per100    if year==2016, abs(`abslist')  vce(cluster `clusterlist')
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c4_rank).xls", br ctitle(OLS levels, type: "agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 

reghdfe `vardep' k_y ln_hc  ln_electric_pc   if year==2016, abs(`abslist')  vce(cluster `clusterlist')
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c4_rank).xls", br ctitle(OLS levels, type: "agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 

reghdfe `vardep' k_y ln_hc  ln_mobile_per100   if year==2016, abs(`abslist')  vce(cluster `clusterlist')
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c4_rank).xls", br ctitle(OLS levels, type: "agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 

reghdfe `vardep' k_y ln_hc ln_broadband_per100 gov_rank_index ln_patent_pc if year==2016, abs(`abslist')  vce(cluster `clusterlist')
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c4_rank).xls", br ctitle(OLS levels, type: "agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 

reghdfe `vardep' k_y ln_hc ln_electric_pc gov_rank_index ln_patent_pc if year==2016, abs(`abslist')  vce(cluster `clusterlist')
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c4_rank).xls", br ctitle(OLS levels, type: "agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 

reghdfe `vardep' k_y ln_hc ln_mobile_per100 gov_rank_index ln_patent_pc if year==2016, abs(`abslist')  vce(cluster `clusterlist')
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c4_rank).xls", br ctitle(OLS levels, type: "agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 

reghdfe `vardep' k_y ln_hc ln_broadband_per100 ln_electric_pc ln_mobile_per100 gov_rank_index ln_patent_pc if year==2016, abs(`abslist')  vce(cluster `clusterlist')
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c4_rank).xls", br ctitle(OLS levels, type: "agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 
}
*




*---------------------------------------------------------------
*Patents, trademarks
foreach typefirm in  "ln_patent_pc"   {
foreach vardep in "ln_`grvar0'" "D_A_phi" "b_phi"  {


*Baseline 
*------------------------------
display "`typefirm'--`vardep'"
reghdfe `vardep'  k_y ln_hc if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c4_rank).xls", br ctitle(OLS levels, type: "agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 


*No governance, no patents, WITH capital
*------------------------------
foreach xxx in ln_infrastructure ln_mobile_per100 ln_broadband_per100 ln_electric_pc   {
display "`xxx'"
display "(1) Infraestructure measured: `xxx'"
reghdfe `vardep' k_y ln_hc `xxx' if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c4_rank).xls", br ctitle(OLS levels, type: "RANK: agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 
}


*Using governance (and oter Z variables + patents)
*------------------------------
reghdfe `vardep' k_y ln_hc  ln_broadband_per100 ln_electric_pc gov_rank_index `typefirm' if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c4_rank).xls", br ctitle(OLS levels, type: "RANK: agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 



}
}
*



/* 

foreach typefirm in  "ln_patent_pc"   {
foreach vardep in "ln_`grvar0'" "D_A_phi" "b_phi"  {


*Baseline 
*------------------------------
display "`typefirm'--`vardep'"
reghdfe `vardep'  k_y ln_hc if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c3_rank).xls", br ctitle(OLS levels, type: "agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 


*No governance, no patents, no capital
*------------------------------
foreach xxx in ln_infrastructure ln_mobile_per100 ln_broadband_per100 ln_electric_pc ln_freshwater_pc  {
display "`xxx'"
display "(1) Infraestructure measured: `xxx'"
reghdfe `vardep' ln_hc `xxx' if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c3_rank).xls", br ctitle(OLS levels, type: "RANK: agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 
}


*No governance, no patents, WITH capital
*------------------------------
foreach xxx in ln_infrastructure ln_mobile_per100 ln_broadband_per100 ln_electric_pc ln_freshwater_pc  {
display "`xxx'"
display "(1) Infraestructure measured: `xxx'"
reghdfe `vardep' k_y ln_hc `xxx' if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c3_rank).xls", br ctitle(OLS levels, type: "RANK: agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 
}


*Using governance 
*------------------------------
foreach xxx in ln_infrastructure ln_mobile_per100 ln_broadband_per100 ln_electric_pc ln_freshwater_pc   {
display "`xxx'"
display "(1) Infraestructure measured: `xxx'"
reghdfe `vardep' k_y ln_hc gov_rank_index `xxx' `typefirm' if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c3_rank).xls", br ctitle(OLS levels, type: "RANK: agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 
}


}
}
*


*Using governance 
*------------------------------
foreach xxx in ln_infrastructure ln_mobile_per100 ln_broadband_per100 ln_electric_pc ln_freshwater_pc ln_air_transp ln_container_port {
display "`xxx'"
display "(1) Infraestructure measured: `xxx'"
reghdfe `vardep' k_y ln_hc gov_index `xxx' `typefirm' if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c3_index).xls", br ctitle(OLS levels, type: "INDEX: agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 
}




*Patents, trademarks
foreach typefirm in  "ln_patent_pc" "ln_researcher_permm"  {
foreach vardep in "ln_`grvar0'" "D_A_phi" "b_phi"  {


*Baseline 
*------------------------------
display "`typefirm'--`vardep'"
reghdfe `vardep'  k_y ln_hc if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c2).xls", br ctitle(OLS levels, type: "agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 


*Using governance 
*------------------------------
foreach xxx in ln_mobile_per100 ln_broadband_per100 ln_electric_pc ln_freshwater_pc ln_air_transp ln_container_port {
display "`xxx'"
display "(1) Infraestructure measured: `xxx'"
reghdfe `vardep' k_y ln_hc gov_rank_index `xxx' `typefirm' if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c2).xls", br ctitle(OLS levels, type: "RANK: agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 
}

*Using Rule of Law 
*------------------------------
foreach xxx in ln_mobile_per100 ln_broadband_per100 ln_electric_pc ln_freshwater_pc ln_air_transp ln_container_port {
display "`xxx'"
display "(1) Infraestructure measured: `xxx'"
reghdfe `vardep' k_y ln_hc RuleofLaw_rank `xxx' `typefirm' if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c2).xls", br ctitle(OLS levels, type: "RANK: agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 
}


*Using governance 
*------------------------------
foreach xxx in ln_mobile_per100 ln_broadband_per100 ln_electric_pc ln_freshwater_pc ln_air_transp ln_container_port {
display "`xxx'"
display "(1) Infraestructure measured: `xxx'"
reghdfe `vardep' k_y ln_hc gov_index `xxx' `typefirm' if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c2).xls", br ctitle(OLS levels, type: "INDEX: agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 
}

*Using Rule of Law 
*------------------------------
foreach xxx in ln_mobile_per100 ln_broadband_per100 ln_electric_pc ln_freshwater_pc ln_air_transp ln_container_port {
display "`xxx'"
display "(1) Infraestructure measured: `xxx'"
reghdfe `vardep' k_y ln_hc RuleofLaw `xxx' `typefirm' if year==`yy', abs(`abslist')  vce(cluster `clusterlist')
mat b = e(b)
mat V = e(V)
global beta: display %-03.2fc round(b[1,1],0.01)
global se_beta: display %-03.2fc round(sqrt(V[1,1]),0.01)
display "$beta, $se_beta, $rho, $se_rho"
outreg2 using "${results}/tables/correlation_table_agg`var0'_revised(c2).xls", br ctitle(OLS levels, type: "INDEX: agg (lp), year `yy'", var_dep: `vardep', FE: `abslist', cluster (`clusterlist')) append 
}
}
}
*

